package utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class PrintResultSetUtil {

    protected final static Logger logger  = LoggerFactory.getLogger(PrintResultSetUtil.class);

    //打印输出 ResultSet 集合中的数据
    public static void Print(ResultSet resultSet) {

        int columnCount = 0;
        ResultSetMetaData md = null;
        try {
            md = resultSet.getMetaData();
            columnCount = md.getColumnCount();
            logger.info("输出 Result <" + resultSet + ">");
            String message;
            while (resultSet.next()) {
                message = "";
                for (int i = 1; i <= columnCount; i++) {
                    message += md.getColumnName(i)+":"+resultSet.getString(i) + "\t";
                }
                logger.info(message);
            }
        } catch (SQLException throwables) {
            logger.info("输出 Result <" + resultSet + "> 失败");
        }

    }

}
